package Thread.Thread_Status;

//线程的状态
//就绪状态/阻塞状态
//Java中的六种状态
/*
1.NEW
当前Thread对象有了但是还没有被调用
2.TERMINATED
当前的Thread对象还存在，但是内核的线程已经销毁（线程的调用已经结束了）
3.RUNNABLE
就绪状态  正在cpu上运行+随时可以去cpu上运行
4.TIMED_WAITING
5.WAITING
6.BLOCKED
456都是线程阻塞状态  这三个都可以通过jconcle来实现动态的线程状态查询
其中BLOCKED是因为锁的竞争所引起的状态
 */
public class Demo17 {
    public static void main(String[] args) throws InterruptedException {
        Thread t=new Thread(()->{
            /*1.NEW
            while(true){
                System.out.println("hello ");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
             */
            /*3.while(true){

            }
             */
            /*4.TIMED_WAITING
            while(true){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
             */
        });
        /*1.NEW
        System.out.println(t.getState());
        t.start();
         */
        /*2.TERMINATED
        System.out.println(t.getState());
        t.start();
        Thread.sleep(1000);
        System.out.println(t.getState());
         */
        /*3.RUNNABLE
        System.out.println(t.getState());
        t.start();
        Thread.sleep(1000);
        System.out.println(t.getState());
        */
        /*4.TIMED_WAITING
        System.out.println(t.getState());
        t.start();
        Thread.sleep(500);
        System.out.println(t.getState());
         */
    }
}
